#include <event2/event.h>
/* Watch out! Including event_struct.h means that your code will not
 * be binary-compatible with future versions of Libevent.*/
#include <event2/event_struct.h>
#include <stdlib.h>
struct event_pair {
    evutil_socket_t fd;
    struct event read_event;
    struct event write_event;
};
void cb_func(evutil_socket_t fd, short what, void* arg);
struct event_pair* event_pair_new(struct event_base * base, evutil_socket_t fd)
{
    struct event_pair* p = malloc(sizeof(struct event_pair));
    if (!p) return NULL;
    p->fd = fd;
    event_assign(&p->read_event, base, fd, EV_READ|EV_PERSIST, cb_func, p);
    event_assign(&p->write_event, base, fd, EV_WRITE|EV_PERSIST, cb_func, p);
    return p;
}
int main()
{
    struct event_base* base = event_base_new();
    struct event_pair* event=event_pair_new(base,fileno(stderr));
    struct timeval five_ses = {5,0};
    event_add(&event->read_event,&five_ses);
    event_base_dispatch(base);

    return 0;
}
void cb_func(evutil_socket_t fd, short what, void* arg)
{
    const char* data = arg;
    printf("Got an event on socket %d:%s%s%s%s [%s]\n",
        (int) fd,
        (what&EV_TIMEOUT) ? " timeout" : "",
        (what&EV_READ) ? " read" : "",
        (what&EV_WRITE) ? " write" : "",
        (what&EV_SIGNAL) ? " signal" : "",
        data);
}